<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------

namespace app\common\model;

/**
 * 用户模型
 */
class Xinjian extends Base{
    /*信件列表*/
    public function liebiao($id){
        $order = "id desc";
        $this_id = $_SESSION['index']['user_auth']['uid'];
        if(1 == $id){
        /*发送列表*/
            $result = $this->db()->where(array('jixin_id'=>$this_id))->order($order)->select();
            foreach($result as $key => $value){
                $list  = model('Member')->where(array('uid'=>$value['shouxin_id']))->find();
                $value['username'] = $list['username'];
                $value['touxiang'] = $list['touxiang'];
            }
            return $result;
        }else{
        /*接收列表*/
            $result = $this->db()->where(array('shouxin_id'=>$this_id))->order($order)->select();
            foreach($result as $key => $value){
                $list  = model('Member')->where(array('uid'=>$value['jixin_id']))->find();
                $value['username'] = $list['username'];
                $value['touxiang'] = $list['touxiang'];
            }
            return $result;
        }
    }
    /*获取sessionId*/
    public function sessionId(){
        return $_SESSION['index']['user_auth']['uid'];
    }
    /*删除信件*/
    public function quchu($id){
       return $this->db()->where(array('Id'=>$id))->delete();
    }
    /*信件详情*/
    public function xindetail($id){
        $result = $this->db()->where(array('id'=>$id))->find();
        if($result){
            $list01  = model('Member')->where(array('uid'=>$result['jixin_id']))->find();
            $list02  = model('Member')->where(array('uid'=>$result['shouxin_id']))->find();
            $result['jixin_name'] = $list01['username'];
            $result['shouxin_name'] = $list02['username'];
            return $result;
        }
    }
}